import Mock from 'mockjs'
var taskCategory = Mock.mock({
  'list|50': [{
    'id|+1': 1,
    categoryName: '任务分类@id',
    'status|1': [0, 1, 2, 3, 4],
    "parentId|1-100": 10,
    categoryCode: '000@id',
    remark: '@csentence(0,50)',
  }]
})
export default [
  // 任务分类分页
  {
    url: '/task/category/getPageList',
    type: 'post',
    response: config => {
      let { pageSize = 10, currentPage = 1 } = config.body
      const total = taskCategory.list.length
      let list = taskCategory.list.slice(pageSize * (currentPage - 1), currentPage * pageSize)
      return {
        code: 20000,
        data: {
          list,
          currentPage,
          pageSize,
          totalCount: total,
          totalPages: (total + pageSize - 1) / pageSize,
        }
      }
    }
  },
  // 任务分类删除
  {
    url: '/task/category/del',
    type: 'post',
    response: config => {
      const { id } = config.body
      if (!id) {
        return {
          code: 403,
          msg: '删除失败',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
        data: id
      }
    }
  },
  // 任务分类增加
  {
    url: '/task/category/add',
    type: 'post',
    response: config => {
      const { categoryName, remark } = config.body
      if (!categoryName) {
        return {
          code: 20203,
          msg: 'categoryName is require',
          data: null
        }
      }
      let data = {
        id: category.id,
        categoryName,
        remark
      }
      return {
        code: 20000,
        msg: '处理成功',
        data,
      }
    }
  },
  // 任务分类修改
  {
    url: '/task/category/edit',
    type: 'post',
    response: config => {
      const { id, categoryName, remark } = config.body
      if (!categoryName || !id) {
        return {
          code: 20203,
          msg: 'id and categoryName is require',
          data: null
        }
      }
      let data = {
        id: category.id,
        categoryName,
        remark
      }
      return {
        code: 20000,
        msg: '处理成功',
        data,
      }
    }
  },
]